package com.lxq.market.servlet;

import com.lxq.market.model.User;
import com.lxq.market.service.AppService;
import com.lxq.market.service.CategoryService;
import com.lxq.market.service.UserService;
import com.lxq.market.util.SessionSignIn;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/admin","/admin/index"})
public class AdminIndexServlet extends HttpServlet {

    SessionSignIn sign=SessionSignIn.getInstance();
    CategoryService categoryService=CategoryService.getInstance();
    AppService appService=AppService.getInstance();
    UserService userService=UserService.getInstance();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user=sign.find(req.getSession().getId());
        req.setAttribute("user",user);
        req.setAttribute("my_app",appService.FindAllByUserId(user.getUserAccount()));
        req.setAttribute("m_category",categoryService.getCategory());
        req.setAttribute("category",categoryService.getCategoryName());
        req.setAttribute("m_all_app",appService.findAll());
        req.setAttribute("m_all_user",userService.findAll());
        req.getRequestDispatcher("/WEB-INF/admin/index.jsp").forward(req,resp);
    }
}
